﻿<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPages/Default.Master" AutoEventWireup="true"
  CodeBehind="Payment.aspx.cs" Inherits="SaleManagement.Web.Pages.Payment" %>

<%@ Register Assembly="DevExpress.Web.v9.1, Version=9.1.4.0, Culture=neutral, PublicKeyToken=5377c8e3b72b4073"
  Namespace="DevExpress.Web.ASPxPopupControl" TagPrefix="dxpc" %>
<%@ Register Assembly="DevExpress.Web.ASPxGridView.v9.1, Version=9.1.4.0, Culture=neutral, PublicKeyToken=5377c8e3b72b4073"
  Namespace="DevExpress.Web.ASPxGridView" TagPrefix="dxwgv" %>
<%@ Register Assembly="DevExpress.Web.ASPxEditors.v9.1, Version=9.1.4.0, Culture=neutral, PublicKeyToken=5377c8e3b72b4073"
  Namespace="DevExpress.Web.ASPxEditors" TagPrefix="dxe" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
  <div id="divContent" runat="server">
    <table width="100%">
      <tr>
        <td class="search_header">
          Thanh toán
        </td>
      </tr>
      <tr>
        <td>
          <table border="0">
            <tr>
              <td style="height: 19px;">
                <asp:Literal ID="Literal5" runat="server" Text="Mã KH"></asp:Literal>
                :
              </td>
              <td style="height: 19px">
                <dxe:ASPxTextBox ID="txtSearchCode" runat="server" Width="120px" ClientInstanceName="txtSearchCode"
                  CssFilePath="~/App_Themes/Aqua/{0}/styles.css" CssPostfix="Aqua">
                  <ValidationSettings>
                    <ErrorImage Height="14px" Url="~/App_Themes/Aqua/Editors/edtError.png" />
                    <ErrorFrameStyle ImageSpacing="4px">
                      <ErrorTextPaddings PaddingLeft="4px" />
                    </ErrorFrameStyle>
                  </ValidationSettings>
                </dxe:ASPxTextBox>
              </td>
              <td style="height: 19px; padding-left: 10px;">
                <asp:Literal ID="Literal6" runat="server" Text="Tên KH"></asp:Literal>
                :
              </td>
              <td style="height: 19px">
                <dxe:ASPxTextBox ID="txtSearchName" runat="server" Width="120px" ClientInstanceName="txtSearchName"
                  CssFilePath="~/App_Themes/Aqua/{0}/styles.css" CssPostfix="Aqua">
                  <ValidationSettings>
                    <ErrorImage Height="14px" Url="~/App_Themes/Aqua/Editors/edtError.png" />
                    <ErrorFrameStyle ImageSpacing="4px">
                      <ErrorTextPaddings PaddingLeft="4px" />
                    </ErrorFrameStyle>
                  </ValidationSettings>
                </dxe:ASPxTextBox>
              </td>
              <td style="height: 19px; padding-left: 10px;">
                <asp:Literal ID="Literal1" runat="server" Text="Số ĐT"></asp:Literal>
                :
              </td>
              <td style="height: 19px">
                <dxe:ASPxTextBox ID="txtSearchPhone" runat="server" Width="120px" ClientInstanceName="txtSearchPhone"
                  CssFilePath="~/App_Themes/Aqua/{0}/styles.css" CssPostfix="Aqua">
                  <ValidationSettings>
                    <ErrorImage Height="14px" Url="~/App_Themes/Aqua/Editors/edtError.png" />
                    <ErrorFrameStyle ImageSpacing="4px">
                      <ErrorTextPaddings PaddingLeft="4px" />
                    </ErrorFrameStyle>
                  </ValidationSettings>
                </dxe:ASPxTextBox>
              </td>
              <td style="height: 19px">
                <dxe:ASPxCheckBox ID="cbxStillDebt" Checked="true" ClientInstanceName="cbxStillDebt"
                  Text="Còn nợ" runat="server" CssFilePath="~/App_Themes/Aqua/{0}/styles.css" CssPostfix="Aqua"
                  TextSpacing="2px">
                </dxe:ASPxCheckBox>
              </td>
              <td style="padding-left: 10px;">
                <dxe:ASPxButton ID="ASPxButton1" runat="server" CssFilePath="~/App_Themes/Aqua/{0}/styles.css"
                  CssPostfix="Aqua" Text="Tìm kiếm" ClientInstanceName="btnSearch">
                  <ClientSideEvents Click="function(s,e){onbtnSearch(s,e);e.processOnServer=false;}" />
                </dxe:ASPxButton>
              </td>
            </tr>
          </table>
        </td>
      </tr>
    </table>
  </div>
  <div style="padding-top: 20px;">
    <dxwgv:ASPxGridView ID="gvPayment" runat="server" Width="100%" AutoGenerateColumns="False"
      CssFilePath="~/App_Themes/Aqua/{0}/styles.css" CssPostfix="Aqua" KeyFieldName="Id"
      OnCustomCallback="gvPayment_CustomCallback" OnPageIndexChanged="gvPayment_PageIndexChanged"
      ClientInstanceName="gvPayment" OnCustomJSProperties="gvPayment_CustomJSProperties">
      <SettingsBehavior AllowDragDrop="false" AllowSort="false" AllowGroup="True" />
      <Templates>
        <GroupRow>
          <table style="font-family: Tahoma; font-size: 11px; color: #294D54; width: 100%;">
            <tr>
              <td style="width: 150px;">
                <asp:Label ID="Label10" runat="server" Text="Khách hàng"></asp:Label>: <span style="text-transform: uppercase;
                  font-weight: bold;">
                  <asp:Label ID="Label13" runat="server" Text='<%#Eval("CustomerName") %>'></asp:Label>
                </span>
              </td>
              <td style="width: 150px;">
                <asp:Label ID="Label1" runat="server" Text="Điện thoại"></asp:Label>: <span style="text-transform: uppercase;
                  font-weight: bold;">
                  <asp:Label ID="Label2" runat="server" Text='<%#Eval("Phone") %>'></asp:Label>
                </span>
              </td>
            </tr>
          </table>
        </GroupRow>
      </Templates>
      <Columns>
        <dxwgv:GridViewDataTextColumn FieldName="CustomerId" Visible="false">
        </dxwgv:GridViewDataTextColumn>
        <dxwgv:GridViewDataTextColumn Name="Command" VisibleIndex="2" Width="15px">
          <HeaderStyle HorizontalAlign="Center" />
          <CellStyle HorizontalAlign="Right">
          </CellStyle>
          <DataItemTemplate>
            <img src="../Images/add.png" title="Thanh toán" onclick="onPayment('<%#Eval("PurchaseId") %>','<%#Eval("CustomerId") %>','<%#Eval("RemainAmount") %>')"
              style="cursor: pointer" alt="" />
          </DataItemTemplate>
        </dxwgv:GridViewDataTextColumn>
        <dxwgv:GridViewDataTextColumn FieldName="PurchaseDate" Width="25%" Caption="Ngày mua hàng"
          VisibleIndex="2">
          <HeaderStyle HorizontalAlign="Center" />
          <CellStyle HorizontalAlign="Center">
          </CellStyle>
          <DataItemTemplate>
            <span onclick="showCustomerInfo('<%#Eval("PurchaseId") %>');" style="cursor: pointer;
              text-decoration: underline; color: #006666; font-weight: bold;">
              <%#Eval("PurchaseDate")%></span>
          </DataItemTemplate>
        </dxwgv:GridViewDataTextColumn>
        <dxwgv:GridViewDataTextColumn FieldName="TotalAmount" Width="25%" Caption="Tổng tiền"
          VisibleIndex="3">
          <HeaderStyle HorizontalAlign="Center" />
          <PropertiesTextEdit DisplayFormatString="#,##0" />
          <CellStyle HorizontalAlign="Right">
          </CellStyle>
        </dxwgv:GridViewDataTextColumn>
        <dxwgv:GridViewDataTextColumn FieldName="TotalPaid" Width="25%" Caption="Đã trả"
          VisibleIndex="3">
          <HeaderStyle HorizontalAlign="Center" />
          <PropertiesTextEdit DisplayFormatString="#,##0" />
          <CellStyle HorizontalAlign="Right">
          </CellStyle>
        </dxwgv:GridViewDataTextColumn>
        <dxwgv:GridViewDataTextColumn FieldName="RemainAmount" Width="25%" Caption="Còn lại"
          VisibleIndex="3">
          <HeaderStyle HorizontalAlign="Center" />
          <PropertiesTextEdit DisplayFormatString="#,##0" />
          <CellStyle HorizontalAlign="Right">
          </CellStyle>
        </dxwgv:GridViewDataTextColumn>
      </Columns>
      <Images ImageFolder="~/App_Themes/Aqua/{0}/">
        <HeaderSortDown Height="5px" Width="6px" Url="~/App_Themes/Aqua/GridView/gvHeaderSortDown.png" />
        <CollapsedButton Height="15px" Width="13px" Url="~/App_Themes/Aqua/GridView/gvCollapsedButton.png" />
        <ExpandedButton Height="15px" Width="13px" Url="~/App_Themes/Aqua/GridView/gvExpandedButton.png" />
        <DetailCollapsedButton Height="15px" Width="13px" Url="~/App_Themes/Aqua/GridView/gvDetailCollapsedButton.png" />
        <DetailExpandedButton Height="15px" Width="13px" Url="~/App_Themes/Aqua/GridView/gvDetailExpandedButton.png" />
        <HeaderFilter Height="19px" Url="~/App_Themes/Aqua/GridView/gvHeaderFilter.png" Width="19px" />
        <HeaderActiveFilter Height="19px" Url="~/App_Themes/Aqua/GridView/gvHeaderFilterActive.png"
          Width="19px" />
        <HeaderSortUp Height="5px" Width="6px" Url="~/App_Themes/Aqua/GridView/gvHeaderSortUp.png" />
        <FilterRowButton Height="13px" Width="13px" />
        <CustomizationWindowClose Width="18px" />
        <PopupEditFormWindowClose Width="18px" />
        <WindowResizer Height="13px" Width="12px" Url="~/App_Themes/Aqua/GridView/WindowResizer.png" />
        <FilterBuilderClose Width="18px" />
      </Images>
      <ClientSideEvents EndCallback="function(s, e) {
	ongvPayment_EndCallback(s,e);
}" />
      <StylesEditors>
        <ProgressBar Height="25px">
        </ProgressBar>
      </StylesEditors>
      <ImagesEditors>
        <CalendarPrevYear Width="23px" />
        <CalendarPrevMonth Width="19px" />
        <CalendarNextMonth Width="19px" />
        <CalendarNextYear Width="23px" />
        <CalendarFastNavPrevYear Height="19px" Url="~/App_Themes/Aqua/Editors/edtCalendarFNPrevYear.png" />
        <CalendarFastNavNextYear Height="19px" Url="~/App_Themes/Aqua/Editors/edtCalendarFNNextYear.png" />
        <DropDownEditDropDown Height="7px" Url="~/App_Themes/Aqua/Editors/edtDropDown.png"
          UrlDisabled="~/App_Themes/Aqua/Editors/edtDropDownDisabled.png" UrlHottracked="~/App_Themes/Aqua/Editors/edtDropDownHottracked.png" />
        <SpinEditIncrement Height="6px" Url="~/App_Themes/Aqua/Editors/edtSpinEditIncrementImage.png"
          UrlDisabled="~/App_Themes/Aqua/Editors/edtSpinEditIncrementDisabledImage.png" UrlHottracked="~/App_Themes/Aqua/Editors/edtSpinEditIncrementHottrackedImage.png"
          UrlPressed="~/App_Themes/Aqua/Editors/edtSpinEditIncrementHottrackedImage.png" />
        <SpinEditDecrement Height="7px" Url="~/App_Themes/Aqua/Editors/edtSpinEditDecrementImage.png"
          UrlDisabled="~/App_Themes/Aqua/Editors/edtSpinEditDecrementDisabledImage.png" UrlHottracked="~/App_Themes/Aqua/Editors/edtSpinEditDecrementHottrackedImage.png"
          UrlPressed="~/App_Themes/Aqua/Editors/edtSpinEditDecrementHottrackedImage.png" />
        <SpinEditLargeIncrement Height="9px" Url="~/App_Themes/Aqua/Editors/edtSpinEditLargeIncImage.png"
          UrlDisabled="~/App_Themes/Aqua/Editors/edtSpinEditLargeIncDisabledImage.png" UrlHottracked="~/App_Themes/Aqua/Editors/edtSpinEditLargeIncHottrackedImage.png"
          UrlPressed="~/App_Themes/Aqua/Editors/edtSpinEditLargeIncHottrackedImage.png" />
        <SpinEditLargeDecrement Height="9px" Url="~/App_Themes/Aqua/Editors/edtSpinEditLargeDecImage.png"
          UrlDisabled="~/App_Themes/Aqua/Editors/edtSpinEditLargeDecDisabledImage.png" UrlHottracked="~/App_Themes/Aqua/Editors/edtSpinEditLargeDecHottrackedImage.png"
          UrlPressed="~/App_Themes/Aqua/Editors/edtSpinEditLargeDecHottrackedImage.png" />
      </ImagesEditors>
      <Styles CssFilePath="~/App_Themes/Aqua/{0}/styles.css" CssPostfix="Aqua">
      </Styles>
      <SettingsLoadingPanel Text="" />
      <SettingsPager>
        <AllButton>
          <Image Height="19px" Width="28px" />
        </AllButton>
        <FirstPageButton>
          <Image Height="19px" Width="23px" />
        </FirstPageButton>
        <LastPageButton>
          <Image Height="19px" Width="23px" />
        </LastPageButton>
        <NextPageButton>
          <Image Height="19px" Width="19px" />
        </NextPageButton>
        <PrevPageButton>
          <Image Height="19px" Width="19px" />
        </PrevPageButton>
      </SettingsPager>
    </dxwgv:ASPxGridView>
  </div>
  <dxpc:ASPxPopupControl ID="pcInfo" ClientInstanceName="pcInfo" runat="server" CssFilePath="~/App_Themes/Aqua/{0}/styles.css"
    CssPostfix="Aqua" ImageFolder="~/App_Themes/Aqua/{0}/" Width="600px" HeaderText=""
    Modal="True" PopupHorizontalAlign="WindowCenter" PopupVerticalAlign="WindowCenter"
    AllowDragging="True">
    <ContentStyle VerticalAlign="Top">
    </ContentStyle>
    <SizeGripImage Height="12px" Width="12px" />
    <ContentCollection>
      <dxpc:PopupControlContentControl>
        <table style="width: 100%" cellpadding="0" cellspacing="0">
          <tr>
            <td style="padding-left: 10px; color: #ff6600; text-transform: uppercase; font-weight: bold;">
              Danh sách thanh toán
            </td>
          </tr>
          <tr style="width: 100%">
            <td style="padding-top: 15px;">
              <dxwgv:ASPxGridView ID="gvPaymentDetail" ClientInstanceName="gvPaymentDetail" runat="server"
                AutoGenerateColumns="False" Width="100%" OnCustomCallback="gvPaymentDetail_CustomCallback"
                CssFilePath="~/App_Themes/Aqua/{0}/styles.css" CssPostfix="Aqua" KeyFieldName="Id">
                <SettingsBehavior AllowDragDrop="False" AllowSort="False" />
                <Styles CssFilePath="~/App_Themes/Aqua/{0}/styles.css" CssPostfix="Aqua">
                </Styles>
                <SettingsPager>
                  <AllButton>
                    <Image Height="19px" />
                  </AllButton>
                  <FirstPageButton>
                    <Image Height="19px" />
                  </FirstPageButton>
                  <LastPageButton>
                    <Image Height="19px" />
                  </LastPageButton>
                  <NextPageButton>
                    <Image Height="19px" />
                  </NextPageButton>
                  <PrevPageButton>
                    <Image Height="19px" />
                  </PrevPageButton>
                </SettingsPager>
                <SettingsLoadingPanel Text="" />
                <Images ImageFolder="~/App_Themes/Aqua/{0}/">
                  <HeaderSortDown Height="5px" Url="~/App_Themes/Aqua/GridView/gvHeaderSortDown.png" />
                  <CollapsedButton Height="15px" Width="11px" Url="~/App_Themes/Aqua/GridView/gvCollapsedButton.png" />
                  <ExpandedButton Height="15px" Url="~/App_Themes/Aqua/GridView/gvExpandedButton.png" />
                  <DetailCollapsedButton Height="15px" Width="9px" Url="~/App_Themes/Aqua/GridView/gvDetailCollapsedButton.png" />
                  <DetailExpandedButton Height="15px" Url="~/App_Themes/Aqua/GridView/gvDetailExpandedButton.png" />
                  <HeaderFilter Height="19px" Url="~/App_Themes/Aqua/GridView/gvHeaderFilter.png" Width="18px" />
                  <HeaderActiveFilter Height="19px" Url="~/App_Themes/Aqua/GridView/gvHeaderFilterActive.png"
                    Width="18px" />
                  <HeaderSortUp Height="5px" Url="~/App_Themes/Aqua/GridView/gvHeaderSortUp.png" />
                  <FilterRowButton Height="13px" Width="13px" />
                  <CustomizationWindowClose Width="17px" />
                  <PopupEditFormWindowClose Width="17px" />
                  <WindowResizer Height="13px" Url="~/App_Themes/Aqua/GridView/WindowResizer.png" />
                  <FilterBuilderClose Width="17px" />
                </Images>
                <Columns>
                  <dxwgv:GridViewDataTextColumn FieldName="Id" Visible="false">
                  </dxwgv:GridViewDataTextColumn>
                  <dxwgv:GridViewDataTextColumn FieldName="Date" VisibleIndex="3" Caption="Ngày thanh toán"
                    Width="40px">
                    <HeaderStyle HorizontalAlign="Center" />
                    <PropertiesTextEdit DisplayFormatString="dd-MM-yyyy" />
                  </dxwgv:GridViewDataTextColumn>
                  <dxwgv:GridViewDataTextColumn FieldName="Amount" VisibleIndex="3" Caption="Số tiền"
                    Width="40px">
                    <HeaderStyle HorizontalAlign="Center" />
                    <PropertiesTextEdit DisplayFormatString="###,###,##0" />
                  </dxwgv:GridViewDataTextColumn>
                  <dxwgv:GridViewDataTextColumn FieldName="Notes" VisibleIndex="3" Caption="Ghi chú">
                    <HeaderStyle HorizontalAlign="Center" />
                  </dxwgv:GridViewDataTextColumn>
                  <dxwgv:GridViewDataTextColumn FieldName="UpdatedBy" VisibleIndex="3" Caption="Người thu tiền"
                    Width="40px">
                    <HeaderStyle HorizontalAlign="Center" />
                  </dxwgv:GridViewDataTextColumn>
                </Columns>
                <ImagesEditors>
                  <CalendarFastNavPrevYear Height="19px" Url="~/App_Themes/Aqua/Editors/edtCalendarFNPrevYear.png" />
                  <CalendarFastNavNextYear Height="19px" Url="~/App_Themes/Aqua/Editors/edtCalendarFNNextYear.png" />
                  <DropDownEditDropDown Height="7px" Url="~/App_Themes/Aqua/Editors/edtDropDown.png"
                    UrlDisabled="~/App_Themes/Aqua/Editors/edtDropDownDisabled.png" UrlHottracked="~/App_Themes/Aqua/Editors/edtDropDownHottracked.png" />
                  <SpinEditIncrement Height="6px" Url="~/App_Themes/Aqua/Editors/edtSpinEditIncrementImage.png"
                    UrlDisabled="~/App_Themes/Aqua/Editors/edtSpinEditIncrementDisabledImage.png" UrlHottracked="~/App_Themes/Aqua/Editors/edtSpinEditIncrementHottrackedImage.png"
                    UrlPressed="~/App_Themes/Aqua/Editors/edtSpinEditIncrementHottrackedImage.png" />
                  <SpinEditDecrement Height="7px" Url="~/App_Themes/Aqua/Editors/edtSpinEditDecrementImage.png"
                    UrlDisabled="~/App_Themes/Aqua/Editors/edtSpinEditDecrementDisabledImage.png" UrlHottracked="~/App_Themes/Aqua/Editors/edtSpinEditDecrementHottrackedImage.png"
                    UrlPressed="~/App_Themes/Aqua/Editors/edtSpinEditDecrementHottrackedImage.png" />
                  <SpinEditLargeIncrement Height="9px" Url="~/App_Themes/Aqua/Editors/edtSpinEditLargeIncImage.png"
                    UrlDisabled="~/App_Themes/Aqua/Editors/edtSpinEditLargeIncDisabledImage.png" UrlHottracked="~/App_Themes/Aqua/Editors/edtSpinEditLargeIncHottrackedImage.png"
                    UrlPressed="~/App_Themes/Aqua/Editors/edtSpinEditLargeIncHottrackedImage.png" />
                  <SpinEditLargeDecrement Height="9px" Url="~/App_Themes/Aqua/Editors/edtSpinEditLargeDecImage.png"
                    UrlDisabled="~/App_Themes/Aqua/Editors/edtSpinEditLargeDecDisabledImage.png" UrlHottracked="~/App_Themes/Aqua/Editors/edtSpinEditLargeDecHottrackedImage.png"
                    UrlPressed="~/App_Themes/Aqua/Editors/edtSpinEditLargeDecHottrackedImage.png" />
                </ImagesEditors>
                <StylesEditors>
                  <ProgressBar Height="25px">
                  </ProgressBar>
                </StylesEditors>
                <ClientSideEvents EndCallback="function(s,e){ongvPaymentDetail_EndCallback(s,e);}" />
              </dxwgv:ASPxGridView>
            </td>
          </tr>
          <tr>
            <td style="padding-top: 10px;">
              <dxe:ASPxButton ID="ASPxButton2" runat="server" AutoPostBack="False" CssFilePath="~/App_Themes/Aqua/{0}/styles.css"
                CssPostfix="Aqua" Text="Đóng">
                <Image Url="../Images/cancel.png" />
                <ClientSideEvents Click="function(s,e){pcInfo.Hide();}" />
              </dxe:ASPxButton>
            </td>
          </tr>
        </table>
        <asp:HiddenField ID="hfPaymentId" runat="server" />
      </dxpc:PopupControlContentControl>
    </ContentCollection>
    <CloseButtonImage Height="16px" Width="17px" />
  </dxpc:ASPxPopupControl>
  <dxpc:ASPxPopupControl ID="pcPayment" ClientInstanceName="pcPayment" runat="server"
    CssFilePath="~/App_Themes/Aqua/{0}/styles.css" CssPostfix="Aqua" ImageFolder="~/App_Themes/Aqua/{0}/"
    Width="461px" PopupHorizontalAlign="WindowCenter" PopupVerticalAlign="WindowCenter"
    HeaderText="Thanh toán" CloseAction="CloseButton" Modal="True">
    <ContentStyle VerticalAlign="Top">
    </ContentStyle>
    <SizeGripImage Height="12px" Width="12px" />
    <ContentCollection>
      <dxpc:PopupControlContentControl>
        <div>
          <dxe:ASPxLabel ID="lblErrorMessage" ClientInstanceName="lblErrorMessage" runat="server"
            Font-Bold="True" ForeColor="#FF3300">
          </dxe:ASPxLabel>
        </div>
        <table width="100%">
          <tr>
            <td>
              <asp:Label ID="Label6" runat="server" Text="Số tiền còn lại"></asp:Label>
              :
            </td>
            <td>
              <dxe:ASPxLabel ID="lblRemain" ClientInstanceName="lblRemain" runat="server">
              </dxe:ASPxLabel>
              <asp:HiddenField ID="hfPurchaseId" runat="server" />
              <asp:HiddenField ID="hfCustomerId" runat="server" />
            </td>
          </tr>
          <tr>
            <td>
              <asp:Label ID="Label1" runat="server" Text="Số tiền thanh toán"></asp:Label>
              :
            </td>
            <td>
              <dxe:ASPxTextBox ID="txtMoney" ClientInstanceName="txtMoney" runat="server" Width="170px"
                CssFilePath="~/App_Themes/Aqua/{0}/styles.css" CssPostfix="Aqua">
                <ValidationSettings>
                  <ErrorImage Height="14px" Url="~/App_Themes/Aqua/Editors/edtError.png" />
                  <ErrorFrameStyle ImageSpacing="4px">
                    <ErrorTextPaddings PaddingLeft="4px" />
                  </ErrorFrameStyle>
                </ValidationSettings>
                <MaskSettings IncludeLiterals="None" Mask="&lt;-9999999999999999999..9999999999999999999g&gt;" />
              </dxe:ASPxTextBox>
            </td>
          </tr>
          <tr>
            <td>
              Ghi chú:
            </td>
            <td>
              <dxe:ASPxMemo ID="mmNote" ClientInstanceName="mmNote" runat="server" CssFilePath="~/App_Themes/Aqua/{0}/styles.css"
                CssPostfix="Aqua" Height="71px" Width="100%">
                <ValidationSettings>
                  <ErrorImage Url="~/App_Themes/Aqua/Editors/edtError.png" />
                  <ErrorFrameStyle ImageSpacing="4px">
                    <ErrorTextPaddings PaddingLeft="4px" />
                  </ErrorFrameStyle>
                </ValidationSettings>
              </dxe:ASPxMemo>
            </td>
          </tr>
          <tr>
            <td>
            </td>
            <td style="padding-top: 4px;">
              <div style="float: left;">
                <dxe:ASPxButton ID="btnSave" runat="server" AutoPostBack="False" CssFilePath="~/App_Themes/Aqua/{0}/styles.css"
                  CssPostfix="Aqua" Text="Lưu">
                  <Image Url="../Images/save.png" />
                  <ClientSideEvents Click="function(s, e) {
	                          onSave();
                        }" />
                </dxe:ASPxButton>
              </div>
              <div style="float: left; padding-left: 3px;">
                <dxe:ASPxButton ID="btnCancel" runat="server" AutoPostBack="False" CssFilePath="~/App_Themes/Aqua/{0}/styles.css"
                  CssPostfix="Aqua" Text="Đóng">
                  <Image Url="../Images/cancel.png" />
                  <ClientSideEvents Click="function(s, e) {
	                            onCancel(); e.processOnServer = false;
                      }" />
                </dxe:ASPxButton>
              </div>
            </td>
          </tr>
        </table>
      </dxpc:PopupControlContentControl>
    </ContentCollection>
    <CloseButtonImage Height="16px" Width="18px" />
  </dxpc:ASPxPopupControl>

  <script type="text/javascript" language="javascript">

    function onbtnSearch(s, e) {
      gvPayment.PerformCallback('Load');
    }

    function ongvPayment_EndCallback(s, e) {
      var para = gvPayment.cpInnerProperty;
      if (para == 'Payment') {
        var result = gvPayment.cpInnerError;
        if (result == '') {
          document.getElementById('<%=hfCustomerId.ClientID %>').value = '';
          document.getElementById('<%=hfPurchaseId.ClientID %>').value = '';
          lblRemain.SetText('');
          mmNote.SetText('');
          alert('Cập nhật thành công');
          pcPayment.Hide();
        }
        else {
          lblErrorMessage.SetText(result);
        }
      }
    }

    function showCustomerInfo(id) {
      setTimeout('gvPaymentDetail.PerformCallback("Load|' + id + '")', 10);
    }

    function ongvPaymentDetail_EndCallback(s, e) {
      pcInfo.Show();
    }

    function onPayment(purchaseId, customerId, remainAmount) {
      lblErrorMessage.SetText('');
      document.getElementById('<%=hfCustomerId.ClientID %>').value = customerId;
      document.getElementById('<%=hfPurchaseId.ClientID %>').value = purchaseId;
      lblRemain.SetText(formatInt(remainAmount));
      txtMoney.SetText('0');
      pcPayment.Show();
    }

    function onSave() {
      if (validateInput()) {
        gvPayment.PerformCallback('Payment');
      }
    }

    function validateInput() {
      var error = '';
      if (txtMoney.GetText() == '' || txtMoney.GetText() == '0') {
        error += 'Bạn phải điền vào số tiền';
      }
      var money = txtMoney.GetValue();
      var remain = lblRemain.GetText();
      if (money > eval(remain)) {
        if (!confirm('Số tiền trả lớn hơn số tiền cần thu')) {
          return false;
        }
      }
      if (error != '') {
        lblErrorMessage.SetText(error);
        return false;
      }
      return true;
    }

    function onCancel() {
      pcPayment.Hide();
    }

    function formatInt(str) {
      if (str == null) {
        return '';
      }
      str = '' + str;
      var strTemp = str;
      if (strTemp.length <= 3)
        return strTemp;
      var strResult = '';
      for (var i = strTemp.length; i >= 0; i--) {
        if (strResult.length > 0 && (strTemp.length - i - 1) % 3 == 0) {
          strResult = ',' + strResult;
        }
        strResult = strTemp.substring(i, i + 1) + strResult;
      }

      return strResult;
    }


  </script>

</asp:Content>
